<h2><%= @header %></h2>

<% if current_volunteer.any_admin? %>
<div style="text-align: right;">
<%= form_tag("/logs/new", :method => "get") do %>
New Item For <%= select_tag(:region_id, options_for_select(@my_admin_regions.collect{ |r| [r.name,r.id] })) %>
<%= submit_tag("Go") %>
<% end %>
</div>
<% end %>

<% if current_volunteer.assignments.length == 0 %>
<p>You haven't been assigned to any regions, so you can't see anything yet. Ask a coordinator for your region to assign you!</p>
<% elsif @shifts.length == 0 %>
<p> 
  No shifts found.
</p>
<% else %>
<table id="my_schedule_table">
  <thead>
  <tr>
    <th> When </th>
    <th> Volunteer </th>
    <th> Donor </th>
    <th> Recipient </th>
    <th> Weight </th>
    <th> Transport Type </th>
    <th> Food Type </th>
    <th> Original Volunteer </th>
    <th> Description </th>
    <th> Time Window </th>
    <th> Notes </th>
    <th> Link </th>
  </tr>
  </thead>
  <tbody>
  <%
  @shifts.each do |shift|
    row_bgcolor = nil
    if shift.volunteer.nil?
      row_bgcolor = "pink"
    elsif shift.volunteer.needs_training
      row_bgcolor = "lightgreen"
    elsif shift.recipient.nil? or shift.donor.nil?
      row_bgcolor = "yellow"
    end
  %>
  <tr <% unless row_bgcolor.nil? %>style="background: <%= row_bgcolor %>;"<% end %>>
    <td> <%= shift.when %> </td>
    <td <% if shift.volunteer.nil? %>style="background: yellow;text-align: center;"<% end %>> 
         <% if shift.volunteer.nil? %>
         <%= link_to 'Take It!', :controller => "logs", :action => "take", :id => shift.id %>
         <% else %>
         <%= link_to shift.volunteer.name, shift.volunteer unless shift.volunteer.nil? %>
         <% end %></td>
    <td> <%= shift.donor != nil ? (link_to shift.donor.name, shift.donor) : ""%> </td>
    <td> <%= shift.recipient != nil ? (link_to shift.recipient.name, shift.recipient) : "" %> </td>
    <td> <%= shift.weight %> </td>
    <td> <%= shift.transport_type.name unless shift.transport_type.nil? %>
    <td> <%= shift.food_type.name unless shift.food_type.nil? %>
    <td> <%= link_to shift.orig_volunteer.name, shift.orig_volunteer unless shift.orig_volunteer.nil? %>
    <td> <%= word_wrap(shift.description,:line_width => 20).gsub("\n","<br>").html_safe unless shift.description.nil? %>
    <td> <%= shift.schedule.time_start.to_s + " - " + shift.schedule.time_stop.to_s unless shift.schedule.nil? %>
    <td> <%= word_wrap(shift.notes,:line_width => 20).gsub("\n","<br>").html_safe unless shift.notes.nil? %>
    <td> <%= link_to 'map', shift.schedule unless shift.schedule.nil? %><br>
         <% if current_volunteer.super_admin? or current_volunteer.region_admin?(shift.region) %>
         <%= link_to "edit", edit_log_path(shift) %><br>
         <%= link_to "delete", shift, :confirm => "Are you sure?", :method => :delete %>
         <% end %></td>
  </tr>
  <% end %>
  </tbody>
</table>
<% end %>
